new Vue({
    el:'#main',
    data:()=>({
        requestUrl:'',
        requestType:'newList',
        page:1,
        pageSize:10,
        pageSum:0,
        id:1,
        list:[],
        checker:[],
        checker_id:-1,
        startDistributeData:[],             // 新订单 开始配货弹框数据
        processingDistributeData:{          // 进行中调配弹框数据
                                    proInfo:{},
                                    storeInfo:{},
                                },        
        processingMore:{},
        processingPickupList:[],
        processingProcessList:[],
        processingStoreOrderList:[],
        warehouseArea:[],
        delList:[],
        processingPauseData:[],
        is_startAtData:{
            pickup_detail:1,
            process_detail:1,
        },
        storeMissingData:[],                // 暂停---缺货登记数据
        storeMissingList:[],                // 暂停---缺货登记数据
        storeMissingSelectData:[],
        checkInfoIsShow:{
            pickup:0,
            process:0,
            makeBox:0,
        },
        status:false,
        checkData:{
            pickupDetail:{
                headData:{},
                bodyData:[]
            },
            processDetail:{
                headData:{},
                bodyData:[]
            },
            salePacksalePack:{
                headData:{},
                bodyData:[]
            },
            logisticsDetail:{
            }
        },
        missingData:[],
        missingDataType:'check',
        storeMissingSaleIds:[],
        isdisabled:false,
        auth_ids:$('#adminauth_ids').text()
        
    }),
    methods:{
        formatUnit:formatUnit,
        myWork(){
            this.requestUrl = "/admin/salemake/list?request=requestAjax&myWork=1";
            this.getdata()
        },
        getdata(){
            $('.loding').show()
            this.pageSum = 0
            var data={
                requestType:this.requestType,
                is_me:this.status,
                page:this.page,
                pageSize:this.pageSize,
            }
            $.ajax({
                url:this.requestUrl,
                type:'post',
                data,
                success:(data)=>{
                    data = JSON.parse(data)

                    if(this.requestType == 'missing'){
                        this.missingData = data.data.list
                    }else{
                        this.list = data.data.list
                    }
                    
                    this.checker = data.data.checker
                    if(data.data.pageSum){
                        this.pageSum = data.data.pageSum
                        this.Resetnav(this.page,data.data.pageSum)
                    }
                    $('.loding').hide()
                }
            })
        },
        Resetnav(pageCurrent, pageSum) {
            //数据总条数
            var myPageCount = pageSum;
            //一页显示多少条
            var myPageSize = this.pageSize;
            //总页数
            var countindex = myPageCount % myPageSize > 0 ? (myPageCount / myPageSize) + 1 : (myPageCount / myPageSize);
            $.jqPaginator('#pagination', {
                totalPages: parseInt(countindex),
                //最多显示多少页
                visiblePages: 5,
                //默认显示第几页
                currentPage: pageCurrent,
                first: '<li class="first"><a href="javascript:;">'+langcon.page_home+'</a></li>',
                prev: '<li class="prev"><a href="javascript:;"><i class="arrow arrow2"></i>'+langcon.previous_page+'</a></li>',
                next: '<li class="next"><a href="javascript:;">'+langcon.next_page+'<i class="arrow arrow3"></i></a></li>',
                last: '<li class="last"><a href="javascript:;">'+langcon.last_page+'</a></li>',
                page: '<li class="page"><a href="javascript:;">{{page}}</a></li>',
                all:'<li class="page"><a href="javascript:;">'+myPageCount+' / '+this.page+'PG , '+this.pageSize+' /PG</a></li>',
                onPageChange:(num, type)=>{
                    if (type == "change") {
                        this.page=num
                        this.getdata()
                    }
                }
            });
        },
        getList(requestType){
            this.requestType = requestType
            this.getdata()
        },
        // 新订单列表按钮-开始配货
        startDistribute(key){
            this.startDistributeData = this.list[key]
            this.checker_id = this.list[key]['checker_id'];
            $('#make_startModal .alert').hide()
        },

        //设置popper组件的配置
        setpopper(e){
            $(e.target).popover({
                trigger: 'hover focus manual',
                placement: ($(e.target).attr("placement") == undefined) ? 'left' : $(e.target).attr("placement"),
                //placement:'left',
                title: $(e.target).attr("title"),
                html: 'true',
                content: $(e.target).find(".content").html(),
                animation: false
            });
        },
        // 判断当前多余的产品qty  在store2area  散货区是否有足够的数量
        setStartDistributeData_(key){
            var data = {
                id:this.startDistributeData.id,// sale_id
                warehouse_id:this.startDistributeData.warehouse_id,
                pro_id:this.startDistributeData['detail'][key]['proInfo'].pro_id,
                prochar_id:this.startDistributeData['detail'][key]['proInfo'].prochar_id,
                allocation_:this.startDistributeData['detail'][key].allocation_,
            }
            $.ajax({
                url:'/admin/salemake/startDistribute?requestType=get',
                type:'post',
                data,
                success:(data)=>{
                    console.log(data)
                    this.startDistributeData['detail'][key]['pickup'] = Number($('#pickup_'+key).val()) + Number(data)
                    $('#pickup_'+key).val(Number($('#pickup_'+key).val()) + Number(data))
                }
            })
        },
        // 新订单设置提货 加工 调货数据
        setStartDistributeData(key,type){

            if(type == 'pickup'){   // 提货
                if(this.startDistributeData['detail'][key]['pickup'] == undefined) this.startDistributeData['detail'][key]['pickup'] = 0

                if(this.startDistributeData['detail'][key].allocation == 0 ){
                    $('#pickup_'+key).val(0) 
                }else if($('#pickup_'+key).val() > this.startDistributeData['detail'][key].allocation){
                    $('#pickup_'+key).val(this.startDistributeData['detail'][key].allocation) 
                    this.startDistributeData['detail'][key]['pickup'] = this.startDistributeData['detail'][key].allocation
                }else{
                    this.startDistributeData['detail'][key]['pickup'] = $('#pickup_'+key).val()
                }

                // 判断当前多余的产品qty  在store2area  散货区是否有足够的数量  allocation_ > 0 表示有散货
                if(this.startDistributeData['detail'][key].allocation_ > 0){
                    this.setStartDistributeData_(key)
                }
            } 

            if(type == 'process') { // 加工
                if(this.startDistributeData['detail'][key]['process'] == undefined) this.startDistributeData['detail'][key]['process'] = 0
                this.startDistributeData['detail'][key]['process'] = $('#process_'+key).val()
            }
            if(type == 'storeOrder') {  // 调货
                if(this.startDistributeData['detail'][key]['storeOrder'] == undefined) this.startDistributeData['detail'][key]['storeOrder'] = 0
                this.startDistributeData['detail'][key]['storeOrder'] = $('#storeOrder_'+key).val()
            }
        },
        setMakeStartModal(){
            if($('#checker_id').val() <= 0){
                this.point({'status':2,'msg':'请选择对货员'},'#make_startModal')
                return false
            }
            this.startDistributeData['checker_id'] = $('#checker_id').val()
            var data = this.startDistributeData
            this.isdisabled = true
            $.ajax({
                url:'/admin/salemake/startDistribute?requestType=save',
                type:'post',
                // data:{data:this.startDistributeData},
                data,
                success:(data)=>{
                    this.isdisabled = false
                    data = JSON.parse(data)
                    this.point(data,'#make_startModal')
                    if(data.status == 1){
                        this.point(data,'.container-fluid')
                        this.getdata()
                    } 
                }
            })
        },
        checkInfo(key){
            this.processingMore = this.list[key]
            console.log(this.processingMore)
            // 提貨頭部詳情
            var pickupDetailHeadData = {
                checker_name:this.processingMore.checker_name,
                status:this.processingMore.maked_at > 0 ? '配貨完成' : '配貨中',
                startTime:this.processingMore.create_make_tim,
                pause_time:this.processingMore.pause_time,
            }
            var data = {
                make_id:this.processingMore.make_id,            
            }
            $.ajax({
                url:'/admin/salemake/checkInfo',
                type:'post',
                data,
                async: false,
                success:(data)=>{
                    data = JSON.parse(data)
                    var pickupDetail = {
                        headData:pickupDetailHeadData,
                        bodyData:data.pickupDetail
                    }
                    var processDetail = {
                        bodyData:data.processDetail
                    }
                    this.checkData={
                        pickupDetail:pickupDetail,
                        processDetail:processDetail,
                        logisticsDetail:data.logisticsDetail,
                        salePacksalePack:data.salePacksalePack
                    }
                }
            })
            console.log(this.checkData.logisticsDetail.teams)
        },
        // nav-tab  进行中--调配按钮
        processingDistribute(key,key1){
            this.processingMore = this.list[key]
            this.processingDistributeData = this.list[key]['detail'][key1]
            $.ajax({
                url:'/admin/salemake/saveProcessingData?request=is_startAt',
                type:'post',
                data:{sale_id:this.processingDistributeData.sale_id,pro_id:this.processingDistributeData.pro_id,prochar_id:this.processingDistributeData.prochar_id},
                success:(data)=>{
                    data = JSON.parse(data)
                    this.is_startAtData = data.data
                }
            })
        },
        changePickup(){
            if($('#pickupEditValue').val() > this.processingDistributeData.storeInfo.store_ctn){
                var data = [];
                data['status'] = 0;
                data['msg'] = '输入的提货数量大于库存';
                $("#make_adjustModalBtn").attr("disabled", true);
                this.point(data,'#make_adjustModal')
            }else{
                $('#make_adjustModal .alert').hide()
                $("#make_adjustModalBtn").attr("disabled", false);

                $('#storePickup').html(this.processingDistributeData.storeInfo.store_ctn -$('#pickupEditValue').val())
                $('#pickoPcs p').html(this.processingDistributeData.proInfo.prochar_qty*$('#pickupEditValue').val())
            }
            
        },
        saveProcessingData(dataName){
            this.isdisabled = true
            $.ajax({
                url:'/admin/salemake/saveProcessingData?request=save',
                type:'post',
                data:{data:this[dataName],packup:$('#pickupEditValue').val(),process:$('#processEditValue').val()},
                success:(data)=>{
                    this.isdisabled = false
                    data = JSON.parse(data)
                    this.point(data,'#make_adjustModal')
                    if(data.status == 1) this.point(data,'.container-fluid')
                }
            })
        },
        // 进行中list 提货/加工/调货按钮
        clickProcessingMore(key,type){
            this.processingMore = this.list[key]
            if(type == 'pickup'){
                this.getWarehouseArea(2,'saveProcessingPickup');

                this.saveProcessingPickup('get',this.processingMore.id)
            } 
            if(type == 'process'){
                this.saveProcessingProcess('get',this.processingMore.id)
            }
            if(type == 'storeOrder'){
                this.saveProcessingStoreOrder('get',this.processingMore.id)
            }
        },
        // 进行中list 暂停按钮
        processingPause(key,type='get'){
            if(type == 'get'){
                var data = {
                    sale_id:this.list[key].id,
                    make_id:this.list[key].make_id,
                }
                    
            }else if(type == 'save'){
                var data = {
                    sale_id:this.processingPauseData.id
                } 
            }
            console.log($('.container-fluid .alert p').html())
            this.isdisabled = true
            $.ajax({
                url:'/admin/salemake/processingPause?requestType='+type,
                type:'post',
                data,
                success:(data)=>{
                    this.isdisabled = false
                    data = JSON.parse(data) 
                    if(type == 'get') this.processingPauseData = data
                    if(type == 'save'){
                        this.point(data,'#make_pauseModal')
                        if(data.status == 1) this.point(data,'.container-fluid')
                    }
                }
            })
            
        },
        // 进行中 更多-提货弹窗-- 添加
        setProcessingPickup(){
            if(this.processingPickupList == undefined) this.processingPickupList = []

            console.log($('#processingPickupProQty').val())
            if($('#processingPickupKey').val() == -1){

                this.processingPickupList.push({
                    sale_id:this.processingMore['detail'][$('#processingPickupPro').val()].sale_id,
                    qty:$('#processingPickupProQty').val(),
                    proInfo:this.processingMore['detail'][$('#processingPickupPro').val()].proInfo,
                    storeInfo:this.processingMore['detail'][$('#processingPickupPro').val()].storeInfo,
                    remark:this.processingMore['detail'][$('#processingPickupPro').val()].remark,

                    processingPickupProQty:$('#processingPickupProQty').val()*this.processingMore['detail'][$('#processingPickupPro').val()].proInfo.prochar_qty,

                    processingPickupArea_id:this.warehouseArea[$('#processingPickupArea').val()].id,
                    processingPickupArea_name:this.warehouseArea[$('#processingPickupArea').val()].name,
                    isset:false
                })
                console.log($('#processingPickupProQty').val()*this.processingMore['detail'][$('#processingPickupPro').val()].proInfo.prochar_qty)
            }else{
                this.processingPickupList[$('#processingPickupKey').val()]['qty'] = this.processingMore['detail'][$('#processingPickupPro').val()].qty
                this.processingPickupList[$('#processingPickupKey').val()]['proInfo'] = this.processingMore['detail'][$('#processingPickupPro').val()].proInfo
                this.processingPickupList[$('#processingPickupKey').val()]['storeInfo'] = this.processingMore['detail'][$('#processingPickupPro').val()].storeInfo
                this.processingPickupList[$('#processingPickupKey').val()]['remark'] = this.processingMore['detail'][$('#processingPickupPro').val()].remark
                this.processingPickupList[$('#processingPickupKey').val()]['processingPickupProQty'] = $('#processingPickupProQty').val()*this.processingMore['detail'][$('#processingPickupPro').val()].proInfo.prochar_qty
                this.processingPickupList[$('#processingPickupKey').val()]['processingPickupArea_id'] = this.warehouseArea[$('#processingPickupArea').val()].id
                this.processingPickupList[$('#processingPickupKey').val()]['processingPickupArea_name'] = this.warehouseArea[$('#processingPickupArea').val()].name
                $('#processingPickupKey').val(-1) 
            }
        },
        // 进行中 更多-提货弹窗-- 通知提货 提交
        saveProcessingPickup(type,sale_id=0){
            $('#make_pickupModal .alert p').hide()
            if(type == 'get') var data = {sale_id:sale_id}
            if(type == 'save'){
                var data = {data:this.processingPickupList}
                for (var i = 0; i < data.data.length; i++) {
                    if(data.data[i].processingPickupArea_id == 0){
                        $('#make_pickupModal .alert p').show()
                        this.point({status:2,msg:'请选择产品：'+data.data[i].proInfo.pro_name+' 提货目的地'},'#make_pickupModal')
                        return false
                    }
                }
            } 
            this.isdisabled = true
            $.ajax({
                url:'/admin/salemake/saveProcessingPickup?requestType='+type,
                type:'post',
                data,
                success:(data)=>{
                    this.isdisabled = false
                    data = JSON.parse(data) 
                    if(type == 'get') this.processingPickupList = data
                    if(type == 'save'){
                        this.point(data,'#make_pickupModal')
                        if(data.status == 1) this.point(data,'.container-fluid')
                    }
                }
            })
        },
        // 进行中 更多-加工弹窗--添加
        setProcessingProcess(){
            if($('#processingProcessKey').val() == -1){
                this.processingProcessList.push({
                    sale_id:this.processingMore['detail'][$('#processingProcessPro').val()].sale_id,
                    qty:this.processingMore['detail'][$('#processingProcessPro').val()].qty,
                    proInfo:this.processingMore['detail'][$('#processingProcessPro').val()].proInfo,
                    storeInfo:this.processingMore['detail'][$('#processingProcessPro').val()].storeInfo,
                    remark:this.processingMore['detail'][$('#processingProcessPro').val()].remark,
                    processingProcessProQty:$('#processingProcessProQty').val(),
                    isset:false
                })
            }else{
                this.processingProcessList[$('#processingProcessKey').val()]['qty'] = this.processingMore['detail'][$('#processingProcessPro').val()].qty
                this.processingProcessList[$('#processingProcessKey').val()]['proInfo'] = this.processingMore['detail'][$('#processingProcessPro').val()].proInfo
                this.processingProcessList[$('#processingProcessKey').val()]['storeInfo'] = this.processingMore['detail'][$('#processingProcessPro').val()].storeInfo
                this.processingProcessList[$('#processingProcessKey').val()]['remark'] = this.processingMore['detail'][$('#processingProcessPro').val()].remark
                this.processingProcessList[$('#processingProcessKey').val()]['processingProcessProQty'] = $('#processingProcessProQty').val()
                $('#processingProcessKey').val(-1) 
            }
        },
        // 进行中 更多-加工弹窗-- 加工 提交   
        saveProcessingProcess(type,sale_id=0){
            if(type == 'get') var data = {sale_id:sale_id}
            if(type == 'save') var data = {data:this.processingProcessList}
            this.isdisabled = true
            $.ajax({
                url:'/admin/salemake/saveProcessingProcess?requestType='+type,
                type:'post',
                data,
                success:(data)=>{
                    this.isdisabled = false
                    data = JSON.parse(data) 
                    if(type == 'get') this.processingProcessList = data
                        console.log(this.processingProcessList)
                    this.point(data,'#make_processModal')
                    if(data.status == 1) this.point(data,'.container-fluid')
                }
            })
        },
        // 进行中 更多-调货弹窗--添加
        setProcessingStoreOrder(){
            if($('#processingStoreOrderKey').val() == -1){
                this.processingStoreOrderList.push({
                    sale_id:this.processingMore['detail'][$('#processingStoreOrderPro').val()].sale_id,
                    qty:this.processingMore['detail'][$('#processingStoreOrderPro').val()].qty,
                    proInfo:this.processingMore['detail'][$('#processingStoreOrderPro').val()].proInfo,
                    storeInfo:this.processingMore['detail'][$('#processingStoreOrderPro').val()].storeInfo,
                    remark:this.processingMore['detail'][$('#processingStoreOrderPro').val()].remark,
                    processingStoreOrderProQty:$('#processingStoreOrderProQty').val(),
                    isset:false
                })
            }else{
                this.processingStoreOrderList[$('#processingStoreOrderKey').val()]['qty'] = this.processingMore['detail'][$('#processingStoreOrderPro').val()].qty
                this.processingStoreOrderList[$('#processingStoreOrderKey').val()]['proInfo'] = this.processingMore['detail'][$('#processingStoreOrderPro').val()].proInfo
                this.processingStoreOrderList[$('#processingStoreOrderKey').val()]['storeInfo'] = this.processingMore['detail'][$('#processingStoreOrderPro').val()].storeInfo
                this.processingStoreOrderList[$('#processingStoreOrderKey').val()]['remark'] = this.processingMore['detail'][$('#processingStoreOrderPro').val()].remark
                this.processingStoreOrderList[$('#processingStoreOrderKey').val()]['processingStoreOrderProQty'] = $('#processingStoreOrderProQty').val()
                $('#processingStoreOrderKey').val(-1) 
            }
        },
        // 进行中 更多-加工弹窗-- 调货 提交   
        saveProcessingStoreOrder(type,sale_id=0){ 
            if(type == 'get') var data = {sale_id:sale_id}
            if(type == 'save') var data = {data:this.processingStoreOrderList}
            this.isdisabled = true
            $.ajax({
                url:'/admin/salemake/saveProcessingStoreOrder?requestType='+type,
                type:'post',
                data,
                success:(data)=>{
                    this.isdisabled = false
                    data = JSON.parse(data) 
                    if(type == 'get') this.processingStoreOrderList = data
                    this.point(data,'#make_ladingModal')
                    if(data.status == 1) this.point(data,'.container-fluid')
                }
            })
        },

        // 暂停 -- 取消暂停
        cancelPause(sale_id){
            var data = {
                sale_id:sale_id
            }
            this.isdisabled = true
            $.ajax({
                url:'/admin/salemake/cancelPause',
                type:'post',
                data,
                success:(data)=>{
                    this.isdisabled = false
                    data = JSON.parse(data) 
                    this.point(data,'.container-fluid')
                    if(data.status == 1) this.getdata()
                }
            })
        },
        // 暂停 -- 解锁
        unLock(sale_id,listIndex=-1){
            if(listIndex >= 0){
                this.clickProcessingMore(listIndex,'process')
            }else{
                var data = {
                    sale_id:sale_id
                }
                this.isdisabled = true
                $.ajax({
                    url:'/admin/salemake/unLock',
                    type:'post',
                    data,
                    success:(data)=>{
                        this.isdisabled = false
                        data = JSON.parse(data) 
                        this.point(data,'.container-fluid')
                        if(data.status == 1) this.getdata()
                    }
                })    
            }

            
        },
        // nav-tab 暂停 ---> 缺货登记
        storeMissing(type,index,key){
            if(type == 'ready'){
                this.storeMissingSelectData = []
                this.storeMissingSelectData = this.list[index]['detail']
            }else if(type == 'selectPro'){
                if($('#storeMissingSelect').val() >= 0){
                    this.storeMissingData = this.storeMissingSelectData[$('#storeMissingSelect').val()]
                    // this.storeMissingData['detail'] = []
                    $.ajax({
                        url:'/admin/salemake/storeMissing?request=getStoreMissing',
                        type:'post',
                        data:{pro_id:this.storeMissingSelectData[$('#storeMissingSelect').val()]['pro_id'],prochar_id:this.storeMissingSelectData[$('#storeMissingSelect').val()]['prochar_id'],sale_id:this.storeMissingSelectData[$('#storeMissingSelect').val()]['sale_id']},
                        success:(data)=>{
                            data = JSON.parse(data) 
                            this.storeMissingList = data.list
                            this.storeMissingSaleIds = data.sale_ids

                            console.log(this.storeMissingSaleIds)

                            var result = this.storeMissingData
                            this.storeMissingData = []
                            result.qty = data.qtySum
                            result.allocation = Math.floor(data.qtySum/result.proInfo.prochar_qty)
                            result.allocation_ = data.qtySum-Math.floor(data.qtySum/result.proInfo.prochar_qty)*result.proInfo.prochar_qty

                            this.storeMissingData = result
                        }
                    })
                }
                    
            }else if(type == 'save'){
                this.isdisabled = true
                $.ajax({
                    url:'/admin/salemake/storeMissing?request=save',
                    type:'post',
                    data:{missing:this.storeMissingData,detail:this.storeMissingList,sale_ids:this.storeMissingSaleIds},
                    success:(data)=>{
                        data = JSON.parse(data) 
                        this.point(data,'#store_missingModal')
                        if(data.status == 1) this.point(data,'.container-fluid')
                        this.isdisabled = false
                    }
                })  
            }
        },
        countQty(){
            var result = this.storeMissingData
            this.storeMissingData = []

            var qtySum = 0;

            for (var i = 0; i < this.storeMissingList.length; i++) {
                if($.inArray(this.storeMissingList[i].sale_id, this.storeMissingSaleIds) >= 0){
                    qtySum += Number(this.storeMissingList[i].qty);
                }
            }

            result.qty = qtySum
            result.allocation = Math.floor(qtySum/result.proInfo.prochar_qty)
            result.allocation_ = qtySum-Math.floor(qtySum/result.proInfo.prochar_qty)*result.proInfo.prochar_qty

            this.storeMissingData = result
        },
        // 暂停 -- 取消配货
        cancelMake(type,listIndex,detailIndex){
            if(type == 'ready'){
                this.processingMore = this.list[listIndex]
                var data = this.list[listIndex]
            }else{
                if(this.processingMore.detail == undefined || this.processingMore.detail.length ==0 ){
                    this.point({status:2,msg:'当前没有需要取消配货的产品'},'#store_missingModal')
                    return false
                } 
                var data = this.processingMore
            }
            this.isdisabled = true
            $.ajax({
                url:'/admin/salemake/cancelMake?requestType='+type,
                type:'post',
                data,
                success:(res)=>{
                    data = JSON.parse(res) 
                    if(type == 'ready'){
                        this.processingMore = data
                    }else{
                        this.point(data,'#store_missingModal')
                        if(data.status == 1) this.point(data,'.container-fluid')
                        this.isdisabled = false
                    }
                }
            }) 
        },
        selectBackArea(detailIndex){
            if($('#backArea_id').val() >= 0){
                var data = {
                    id:this.processingMore['detail'][detailIndex]['backArea'][$('#backArea_id').val()].id,
                    name:this.processingMore['detail'][detailIndex]['backArea'][$('#backArea_id').val()].name,
                    checked:true
                }
                this.processingMore['detail'][detailIndex]['backArea'][$('#backArea_id').val()] = data
            }
        },
        // 取消 --- 恢复
        cancelRestore(type,data){
            if(type == 'get'){
                this.processingMore = data
            }else if(type == 'save'){
                this.isdisabled = true
                $.ajax({
                    url:'/admin/salemake/cancelRestore',
                    type:'post',
                    data:{'sale_id':data},
                    success:(res)=>{
                        data = JSON.parse(res) 
                        if(type == 'ready'){
                            this.processingMore = data
                        }else{
                            this.point(data,'#store_missingModal')
                            if(data.status == 1) this.point(data,'.container-fluid')
                        }
                        this.isdisabled = false
                    }
                }) 
            }
        },
        // 缺货登记 -- 查看
        missingCheck(missingData){
            this.getmissingData(missingData)
            this.missingDataType = 'check'
        },
        getmissingData(missingData){
            this.storeMissingData = missingData
            $.ajax({
                url:'/admin/salemake/missingCheck',
                type:'post',
                data:{pro_id:missingData.pro_id,prochar_id:missingData.prochar_id,sale_id:missingData.sale_id},
                success:(data)=>{
                    data = JSON.parse(data) 
                    this.storeMissingList = data.list
                    this.storeMissingSaleIds = data.sale_ids
                    console.log(this.storeMissingList)
                    var result = this.storeMissingData
                    this.storeMissingData = []
                    result.qty = data.qtySum
                    result.allocation = Math.floor(data.qtySum/result.proInfo.prochar_qty)
                    result.allocation_ = data.qtySum-Math.floor(data.qtySum/result.proInfo.prochar_qty)*result.proInfo.prochar_qty

                    this.storeMissingData = result
                }
            })
        },
        missingEdit(missingData){
            if(missingData == 'save'){
                this.isdisabled = true
                $.ajax({
                    url:'/admin/salemake/storeMissing?request=save',
                    type:'post',
                    data:{missing:this.storeMissingData,detail:this.storeMissingList,sale_ids:this.storeMissingSaleIds},
                    success:(data)=>{
                        data = JSON.parse(data) 
                        this.point(data,'#store_missingModal')
                        if(data.status == 1) this.point(data,'.container-fluid')
                        this.isdisabled = false
                        this.getdata()
                    }
                })
            }else{
                this.getmissingData(missingData)
                this.missingDataType = 'edit'    
            }
        },
        missingCancel(missing_id){
            $.ajax({
                url:'/admin/salemake/missingCancel',
                type:'post',
                data:{missing_id:missing_id},
                success:(data)=>{
                    data = JSON.parse(data) 
                    this.point(data,'.container-fluid')
                    this.getdata()
                }
            })
        },
        print(key){
            $.ajax({
                url:'/admin/salemake/print',
                type:'post',
                data,
                success:(data)=>{
                }
            })
        },









        // 编辑/删除
        editAndDel(key,type,dataName){
            if(type == 'del'){
                // 判断是否删除已存入数据表的数据。
                if(this[dataName][key]['isset'] == undefined){
                    if(this.delList[dataName] == undefined) this.delList[dataName] = []
                    this.delList[dataName].push(this[dataName][key]['id']);    
                }
                this[dataName].splice(key,1)
            }else{
                // 进行中 提货编辑
                if(dataName == 'processingPickupList'){
                    $.each(this.processingMore.detail, (key1, value) => {
                        if(value.pro_id == this[dataName][key]['proInfo']['pro_id'] &&  value.prochar_id == this[dataName][key]['proInfo']['prochar_id']){
                            $('#processingPickupPro').val(key1)
                        } 
                    });
                    $.each(this.warehouseArea, (key1, value) => {
                        if( value.id == this[dataName][key]['processingPickupArea_id'] ){
                            $('#processingPickupArea').val(key1)
                        } 
                    });
                    console.log(this[dataName][key])
                    $('#processingPickupProQty').val(this[dataName][key]['processingPickupProQty']/this[dataName][key].proInfo.prochar_qty)
                    $('#processingPickupKey').val(key)
                // 进行中 加工编辑    
                }else if(dataName == 'processingProcessList'){
                    $.each(this.processingMore.detail, (key1, value) => {
                        if(value.pro_id == this[dataName][key]['proInfo']['pro_id'] &&  value.prochar_id == this[dataName][key]['proInfo']['prochar_id']){
                            $('#processingProcessPro').val(key1)
                        } 
                    });
                    $('#processingProcessProQty').val(this[dataName][key]['processingProcessProQty'])
                    $('#processingProcessKey').val(key)
                }else if(dataName == 'processingStoreOrderList'){
                    $.each(this.processingMore.detail, (key1, value) => {
                        if(value.pro_id == this[dataName][key]['proInfo']['pro_id'] &&  value.prochar_id == this[dataName][key]['proInfo']['prochar_id']){
                            $('#processingStoreOrderPro').val(key1)
                        } 
                    });
                    $('#processingStoreOrderProQty').val(this[dataName][key]['processingStoreOrderProQty'])
                    $('#processingStoreOrderKey').val(key)
                }
            }
        },

        // 获取仓库区域
        getWarehouseArea(id,func){
            $.ajax({
                url:'/admin/salemake/'+func+'?requestType=warehouseArea&id='+id,
                type:'get',
                success:(data)=>{
                    data = JSON.parse(data)
                    this.warehouseArea = data;
                }
            })
        },
        point(data,modelId){
            change_mes_type(modelId+' .alert',data.status)
            if(data.status == 1){
                if(modelId != '.container-fluid') $(modelId).modal('toggle')
                $(modelId+' .alert').show()
                $(modelId+' .alert p').html('*'+data.msg+'<br>')
            }else{
                $(modelId+' .alert').show()
                $(modelId+' .alert p').html('*'+data.msg+'<br>')
            }
        },

    },
    mounted(){
        this.requestUrl = "/admin/salemake/list?request=requestAjax";
        this.getdata()
    },
})